package org.nfIt.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Component;

import java.lang.reflect.Array;
import java.util.Arrays;

/**
 * ClossName:myAdvice
 * Pakage:org.nfIt.aop
 * Description
 *
 * @Author L
 * @Create 2024/5/4 23:44
 * @Version 2023.1.3x
 */
@Component
//把这类当成aop解析
@Aspect
public class myAdvice {

    @Pointcut("execution(* org.nfIt.dao.BookDao.update(..))")
    public void pt(){}

//    @Before("pt()")
   public void before(JoinPoint joinPoint){
        Object[] args = joinPoint.getArgs();
        System.out.println("获取到的参数："+Arrays.toString(args));
        System.out.println("前置通知。。。before run");
   }
//   @After("pt()")
   public void after(JoinPoint joinPoint){
       Object[] args = joinPoint.getArgs();
       System.out.println("获取到的参数："+Arrays.toString(args));
       System.out.println("后置通知。。。after run");
   }

//   @Around("pt()")
   public void around(ProceedingJoinPoint pjp) throws Throwable {
       System.out.println("before run");

       Object[] args = pjp.getArgs();
       System.out.println("获取到的参数："+Arrays.toString(args));
       args[0] = 666;
       Object proceed = pjp.proceed(args);
       System.out.println(proceed);

       //表示对原始方法的调用
       pjp.proceed();

       System.out.println("after run");

   }


    @AfterReturning(value = "pt()",returning = "name")
   public void afterThrowing(Object name) {
         System.out.println("返回后通知。。。afterThrowing run"+name);
   }

   //    @AfterThrowing(value = "pt()")
   public void afterReturning(){
        System.out.println("抛异常后通知。。。afterReturning run");
    }
}
